package cn.nju.zyy.auction;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

public class Category {

	private Long id;
	private String name;
	private Category parentCategory;
	private Set childCategories = new HashSet();
	private Set items = new HashSet();

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Category() {
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Category getParentCategory() {
		return parentCategory;
	}

	public void setParentCategory(Category parentCategory) {
		this.parentCategory = parentCategory;
	}

	public Set getChildCategories() {
		return Collections.unmodifiableSet(childCategories);
	}

	private void setChildCategories(Set childCategories) {
		this.childCategories = childCategories;
	}

	public void addChildCategory(Category childCategory) {
		if (childCategory == null)
			throw new IllegalArgumentException("Null child category!");
		if (childCategory.getParentCategory() != null)
			childCategory.getParentCategory()
					.getChildCategories()
					.remove(childCategory);
		childCategory.setParentCategory(this);
		childCategories.add(childCategory);
	}

	public Set getItems() {
		return items;
	}

	public void setItems(Set items) {
		this.items = items;
	}
}
